package com.itsm.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itsm.entity.File;
import com.itsm.entity.User;
import com.itsm.service.mapper.FileMapper;
import com.itsm.service.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private FileMapper fileMapper;



    /**
     * 按照指定角色进行人员查询
     * @param duty 指定角色
     * @return 指定人员
     */
    public List<User> selectName(String duty){
        QueryWrapper<User> wrapper = new QueryWrapper();
        wrapper.eq("duty_name",duty).select("name","id");;
        List<User> users = userMapper.selectList(wrapper);
        return users;
    }

    /**
     * 通过user表获取个人信息
     * @param userid 企微id
     * @return 个人信息
     */
    public User selectUser(String userid){
        return userMapper.getUserById(userid);
    }

    public Integer updateUser(User user){

        return userMapper.updateById(user);
    }

    public String getSub(String userid){

        return userMapper.getUserSup(userid);
    }

//    //获取IT审批人姓名
//    public String getItName(){
//
//        return userMapper.getItSup();
//    }
    public Integer addUser(User user){

        return userMapper.insert(user);
    }

    public List<User> getAllUser(){
        return userMapper.getAllUser();
    }

    public List<File> getAllName(String userid){
        User user = userMapper.selectById(userid);
        if(user.getPlantAll()!=1){
            return fileMapper.getAllName(user.getPlant());
        }else{
            return fileMapper.getAllName1();
        }
    }

    public List<User> selectEn(String name){
        if(userMapper.getUserByName(name).getPost()!=0){
            return userMapper.getItEnUser();
        }
        return null;
    }
}
